import beans.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Creared with IntelliJ IDEA.
 * Description:为什么要有五大类注解：让代码的可读性提高，让程序员能够直观的判断当前类的业务用途，
 * 五大类之间的关系是啥？四个类都是基于Component实现的，这是父类
 * 为啥bean的名称是小驼峰，通过查看源代码可以看出来，要是类名的第一个和第二个字符都是大写的就是原类名，不满足这个条件的话就是小驼峰
 * User:yxd
 * Date:2022-07-03
 * Time:16:22
 */
public class Main {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
        BeanScope1 beanScope1 = context.getBean(BeanScope1.class);
        User user1 = beanScope1.getUser();
        System.out.println("BeanScope1:" + user1);
        BeanScope2 beanScope2 = context.getBean(BeanScope2.class);
        User user2 = beanScope2.getUser();
        System.out.println("BeanScope2:" + user2);
    }
    public static void main1(String[] args) {
        //先得到上下文对象
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
        UserController controller = context.getBean("userController",UserController.class);
        controller.func();
        //得到bean,那这里就有个问题  id到底是什么呢？这里就需要使用到类名的小驼峰模式了
//        UserController controller = context.getBean("userController",UserController.class);
//        //使用bean
//        controller.func();
//        UserService service = context.getBean("userService",UserService.class);
//        service.func();
        //这里的id就是方法名,再使用小驼峰就不可以了
//        User user = context.getBean("user",User.class);
//        System.out.println(user);

//        UserController user = context.getBean(UserController.class);
//        user.func();
//        UserService service = context.getBean("userService",UserService.class);
//        service.func();

//         UserRepository repository = context.getBean("userRepository",UserRepository.class);
//         //使用bean
//         repository.func();
//        UserConfig config = context.getBean("userConfig",UserConfig.class);
//        config.func();
//        UserComponent component = context.getBean("userComponent",UserComponent.class);
//        component.func();
    }
}
